package org.example.spring.self.demo.s4;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * 文件描述
 *
 * @author yezhou41127
 * @date: 2022年08月01日
 */
public class Bean1 {

	private Bean2 bean2;

	public Bean2 getBean2() {
		return bean2;
	}

	@Autowired
	public void setBean2(Bean2 bean2) {
		System.out.println("bean2 autowired " + bean2);
		this.bean2 = bean2;
	}

	private Bean3 bean3;

	public Bean3 getBean3() {
		return bean3;
	}

	@Resource
	public void setBean3(Bean3 bean3) {
		System.out.println("bean3 resource " + bean3);
		this.bean3 = bean3;
	}

	private String javaHome;

	public String getJavaHome() {
		return javaHome;
	}

	@Autowired
	public void setJavaHome(@Value("${JAVA_HOME}") String javaHome) {
		System.out.println("Value " + javaHome);
		this.javaHome = javaHome;
	}

	@PostConstruct
	public void init() {
		System.out.println("初始化");
	}

	@PreDestroy
	public void destroy() {
		System.out.println("销毁");
	}

	@Override
	public String toString() {
		return "Bean1{" +
				"bean2=" + bean2 +
				", bean3=" + bean3 +
				", javaHome='" + javaHome + '\'' +
				'}';
	}
}
